package com.linglingC.controller;


import com.linglingC.pojo.*;
import com.linglingC.service.EmplyeeService;
import com.linglingC.service.PropertyItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class PropertyItemContrroller {

    @Autowired
    private PropertyItemService propertyItemService;


    @GetMapping("/propertyItemFindAll")
    public Result propertyItemFindAll(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pageSize
                                             ){
        log.info("物业项目表分页查询:{} {}",page,pageSize);

        PageBean pageBean=propertyItemService.findAll(page,pageSize);

        return Result.success(pageBean);
    }

    @GetMapping("/propertyItemSelect")
    public Result propertyItemSelect(String key,String value,@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("物业项目表条件: 字段:{} 值:{}",key,value );

        PageBean pageBean=propertyItemService.select(key,value,page,pageSize);

        return  Result.success(pageBean);
    }

    @PostMapping("/insertPropertyItem")
    private Result insertPropertyItem(@RequestBody PropertyItem propertyItem){
        log.info("添加项目: {}",propertyItem);
        propertyItemService.addPropertyItem(propertyItem);
        return Result.success();
    }

    @DeleteMapping("/propertyItemDelete/{ID}")
    private Result propertyItemDelete(@PathVariable Integer ID){
        log.info("删除单一项目: ID: {}",ID);
        propertyItemService.deleteOnePropertyItem(ID);
        return Result.success("删除成功");
    }

    @PutMapping("editPropertyItem")
    public Result editpropertyItem(@RequestBody PropertyItem propertyItem){
        log.info("修改项目信息: {}",propertyItem);
        propertyItemService.editPropertyItem(propertyItem);
        return Result.success();
    }

    @GetMapping("/itemNameID")
    public Result itemNameID(){
        List<PropertyItemNameId> p=propertyItemService.selectNameID();
        return Result.success(p);
    }

}
